// 命名函数
function addNamed(x:number, y:number){
    return x+y;
}

// 匿名函数，后面不能加 =>
let addNoNamed = function(x:number, y:number){
    return x+y;
}
// 定义变量为后面的函数类型，后面必须是 =>，和上面编译成js代码是一样的！！
let myAdd: (x:number, y:number)=>number = 
function(x: number, y: number): number { return x+y; };

myAdd = function(x: number, y: number): number { return x+y; };


function buildName(firstName: string, lastName?: string) {
      if (lastName)
          return firstName + " " + lastName;
      else
          return firstName;
}
let result1 = buildName("Bob"); // works correctly now
//let result2 = buildName("Bob", "Adams", "Sr."); // error, too many parameters
let result3 = buildName("Bob", "Adams"); // ah, just right

function buildName2(firstName: string, lastName = "Smith") {
    return firstName + " " + lastName;
}




